package bulk_param.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import bulk_param.dao.SelectBoxOpenNumSpeDao;
import bulk_param.modele.JTextFieldLimit;
import bulk_param.modele.WiderDropDownCombo;
import bulk_param.numspe.controller.ButtonNumSpeOuvertureController;
import bulk_param.numspe.controller.ColorErrorNumSpeController;
import bulk_param.numspe.controller.SetSelectedBoxNumSpeController;

import com.toedter.calendar.JDateChooser;
import com.toedter.calendar.JTextFieldDateEditor;

public class NumSpe_Open_View extends JPanel{	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		
	private Font font = new Font("Comic Sans MS", Font.BOLD, 12);
	private Font fontBouton = new Font("Broadway", Font.BOLD, 12);
	private JPanel panelOpenPoint;
	private JPanel contact_Panel;
	private JPanel panelTrafic;
	public JButton btValider ;
	public JTextFieldDateEditor dateEditor;
	public JDateChooser dateChooser;
	private String selectDate = "Séléction de Date";
	public JRadioButton fixe_geo,num_09, mobile;
	public JLabel lbTarifs,lbZABPQ, lbActiveDt,lbZLT ;
	public JTextField txtZABPQ, txtZLT ;
	
	public WiderDropDownCombo widerDropDownCombo;
	
	//Liste des contenus combobox
	public ArrayList<String> listTarification;
	
	public SelectBoxOpenNumSpeDao selectBoxOpenNumSpeDao ;
	
	public NumSpe_Open_View(){
		
	}
	
	public JPanel panelOpenNumSepciaux(){		
		
		//Remplissage des contenue des combobox via BD
		selectBoxOpenNumSpeDao = new SelectBoxOpenNumSpeDao();
		selectBoxOpenNumSpeDao.getConnection();
        listTarification = selectBoxOpenNumSpeDao.listTarification();
        selectBoxOpenNumSpeDao.closeConnection();		
		
		//Panel Open_Point
		panelOpenPoint = new JPanel();
		panelOpenPoint.setLayout(new BorderLayout());
					
		
		//GridBagLayout pour les champs d'activation du point ZABPQ
        contact_Panel = new JPanel();
        contact_Panel.setLayout(new GridBagLayout());
        
        widerDropDownCombo = new WiderDropDownCombo();
        
		// libelle premiere ligne        
        //Point_region
        GridBagConstraints gridBagConstraintsPointRegion = new GridBagConstraints();
        lbTarifs = new JLabel("Tarifs : ");
        gridBagConstraintsPointRegion.gridx = 1;
        gridBagConstraintsPointRegion.gridy = 0;
        gridBagConstraintsPointRegion.insets = new Insets(20, 5, 20, 5);
        gridBagConstraintsPointRegion.anchor = gridBagConstraintsPointRegion.WEST;
        contact_Panel.add(lbTarifs, gridBagConstraintsPointRegion);
        
        GridBagConstraints gridBagConstraintsSelectPointRegion = new GridBagConstraints();
        widerDropDownCombo.addItem(" ");
        for (int i=0;i<listTarification.size();i++){
        	widerDropDownCombo.addItem(listTarification.get(i));
        }
        widerDropDownCombo.setPreferredSize(new Dimension(250, 21));
        widerDropDownCombo.setWide(true);
        gridBagConstraintsSelectPointRegion.gridx = 2;
        gridBagConstraintsSelectPointRegion.gridy = 0;
        gridBagConstraintsSelectPointRegion.insets = new Insets(20, 5, 20, 10);
        gridBagConstraintsSelectPointRegion.anchor = gridBagConstraintsSelectPointRegion.WEST;
        contact_Panel.add(widerDropDownCombo, gridBagConstraintsSelectPointRegion);
            
        //POINT ZABPQ
        GridBagConstraints gridBagConstraintsPointZABPQ = new GridBagConstraints();
        lbZABPQ = new JLabel("Point(03BPQ) : ");
        lbZABPQ.setPreferredSize(new Dimension(130, 21));
        gridBagConstraintsPointZABPQ.gridx = 3;
        gridBagConstraintsPointZABPQ.gridy = 0;
        gridBagConstraintsPointZABPQ.insets = new Insets(20, 5, 20, 5);
        gridBagConstraintsPointZABPQ.anchor = gridBagConstraintsPointZABPQ.WEST;
        contact_Panel.add(lbZABPQ, gridBagConstraintsPointZABPQ);
        
        GridBagConstraints gridBagConstraintsPoint = new GridBagConstraints();
        txtZABPQ = new JTextField(12);
        txtZABPQ.setDocument(new JTextFieldLimit(7));
        gridBagConstraintsPoint.gridx = 4;
        gridBagConstraintsPoint.gridy = 0;
        gridBagConstraintsPoint.insets = new Insets(20, 5, 20, 10);
        gridBagConstraintsPoint.anchor = gridBagConstraintsPoint.WEST;
        contact_Panel.add(txtZABPQ, gridBagConstraintsPoint);
        
     // libelle deuxieme ligne
        GridBagConstraints gridBagConstraintsZLT = new GridBagConstraints();
        lbZLT = new JLabel("ZLT : ");
        gridBagConstraintsZLT.gridx = 1;
        gridBagConstraintsZLT.gridy = 1;
        gridBagConstraintsZLT.insets = new Insets(20, 5, 20, 5);
        gridBagConstraintsZLT.anchor = gridBagConstraintsZLT.WEST;
        contact_Panel.add(lbZLT, gridBagConstraintsZLT);
        
        GridBagConstraints gridBagConstraintsTxtZLT = new GridBagConstraints();
        txtZLT = new JTextField();
        txtZLT.setPreferredSize(new Dimension(250, 21));
        txtZLT.setEnabled(false);
        gridBagConstraintsTxtZLT.gridx = 2;
        gridBagConstraintsTxtZLT.gridy = 1;
        gridBagConstraintsTxtZLT.insets = new Insets(20, 5, 20, 10);
        gridBagConstraintsTxtZLT.anchor = gridBagConstraintsTxtZLT.WEST;
        contact_Panel.add(txtZLT, gridBagConstraintsTxtZLT);
        
        //Date activation
        GridBagConstraints gridBagConstraintsActiveDt = new GridBagConstraints();
        lbActiveDt = new JLabel("Date d'activation : ");
        gridBagConstraintsActiveDt.gridx = 3;
        gridBagConstraintsActiveDt.gridy = 1;
        gridBagConstraintsActiveDt.insets = new Insets(20, 5, 20, 5);
        gridBagConstraintsActiveDt.anchor = gridBagConstraintsActiveDt.WEST;
        contact_Panel.add(lbActiveDt, gridBagConstraintsActiveDt);
        
        GridBagConstraints gridBagConstraintsTxtActiveDt = new GridBagConstraints();     
        dateChooser = new JDateChooser();
        dateChooser.setDateFormatString("dd/MM/yyyy");
        dateChooser.setPreferredSize(new Dimension(135, 21));
        dateEditor = (JTextFieldDateEditor)dateChooser.getDateEditor();
        dateEditor.setEditable(false);
        dateEditor.setText(selectDate);
        dateEditor.setForeground(Color.gray);
        gridBagConstraintsTxtActiveDt.gridx = 4;
        gridBagConstraintsTxtActiveDt.gridy = 1;
        gridBagConstraintsTxtActiveDt.insets = new Insets(20, 5, 20, 10);
        gridBagConstraintsTxtActiveDt.anchor = gridBagConstraintsTxtActiveDt.WEST;
        contact_Panel.add(dateChooser, gridBagConstraintsTxtActiveDt);
       
        //lieblle boutton
        GridBagConstraints gridBagConstraintsbtValider = new GridBagConstraints();
        btValider = new JButton("Valider");
        btValider.setPreferredSize(new Dimension(100,21));
        btValider.setBackground(Color.black);
        btValider.setFont(fontBouton);
        btValider.setForeground(Color.getHSBColor(39,233,255));
        gridBagConstraintsbtValider.gridx = 3;
        gridBagConstraintsbtValider.gridy = 3;
        gridBagConstraintsbtValider.insets = new Insets(20, 5, 20, 5);
        gridBagConstraintsbtValider.anchor = gridBagConstraintsbtValider.WEST;
        contact_Panel.add(btValider, gridBagConstraintsbtValider);
        
      //Type de trafic
  		panelTrafic= new JPanel();
  		Border titledBorderTrafic = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.getHSBColor(93/360F, 0.57F, 0.60F)), "Numéros Spéciaux :", TitledBorder.LEFT, TitledBorder.TOP, font, Color.getHSBColor(93/255F, 0.57F, 0.60F));
  		panelTrafic.setBorder(BorderFactory.createTitledBorder(titledBorderTrafic));  		
  		panelTrafic.add(contact_Panel);                  
       
		panelOpenPoint.add(panelTrafic,BorderLayout.CENTER);
		
		//Action Bouton valider
		btValider.addActionListener(new ButtonNumSpeOuvertureController(this));
		
		//Changement des bordures de textfield en cas d'erreur
		widerDropDownCombo.addMouseListener(new ColorErrorNumSpeController(this));
		txtZABPQ.addMouseListener(new ColorErrorNumSpeController(this));
		dateEditor.addMouseListener(new ColorErrorNumSpeController(this));
		dateChooser.addMouseListener(new ColorErrorNumSpeController(this));
		
		//changement de la selectbox
		widerDropDownCombo.addActionListener(new SetSelectedBoxNumSpeController(this));
				
		return panelOpenPoint;
						
	}		
}
